package com.edvinli.service.impl;

import com.edvinli.entity.ClazzCountOption;
import com.edvinli.entity.JobOption;
import com.edvinli.entity.StudentDegreeOption;
import com.edvinli.mapper.ClazzMapper;
import com.edvinli.mapper.EmpMapper;
import com.edvinli.mapper.StudentMapper;
import com.edvinli.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    private EmpMapper empMapper;

    @Autowired
    private StudentMapper studentMapper;

    /**
     * 统计各职位员工人数
     * @return
     */
    @Override
    public JobOption empJobData() {
        List<Map> list = empMapper.countByJob();

        List jobList = list.stream().map(item -> item.get("pos")).toList();
        List sumList = list.stream().map(item -> item.get("sum")).toList();

        return new JobOption(jobList, sumList);
    }

    /**
     * 统计员工性别
     * @return
     */
    @Override
    public List<Map> getEmpGenderData() {
        return empMapper.countByGender();
    }
    /**
     * 统计班级人数
     * @return
     */

    @Override
    public ClazzCountOption getStudentCountData() {

        List<Map<String, Object>> list = studentMapper.getStudentCount();
        if(!CollectionUtils.isEmpty(list)){
            List<Object> clazzList = list.stream().map(map -> {
                return map.get("cname");
            }).toList();

            List<Object> dataList = list.stream().map(map -> {
                return map.get("scount");
            }).toList();

            return new ClazzCountOption(clazzList, dataList);
        }
        return null;
    }

    /**
     * 统计学员学历
     * @return
     */
    @Override
    public List<Map> getStudentDegree() {
        return studentMapper.getStudentDegree();
    }


}
